package com.platform.tony.config;

import com.google.common.collect.Lists;


import com.platform.tony.dto.UserDto;
import com.platform.tony.entity.Role;
import com.platform.tony.entity.User;
import com.platform.tony.mapper.UserMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class AuthServiceImpl implements UserDetailsService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {

        User user = userMapper.queryUserByName(username);

        UserDto dto = new UserDto();
        dto.setId(123456L);
        dto.setUsername(username);
        dto.setPassword("123456");
        dto.setEnabled(true);
        dto.setAccountNonExpired(true);
        dto.setAccountNonLocked(true);
        dto.setCredentialsNonExpired(true);
        dto.setRoles(Lists.newArrayList(new Role("ADMIN"), new Role("USER")));
        return dto;
    }


}
